//
//  DongTaiQuanViewController.m
//  NC-Trendy
//
//  Created by brother on 16/2/23.
//  Copyright © 2016年 liang. All rights reserved.
//

#import "DongTaiQuanViewController.h"

@interface DongTaiQuanViewController ()

//定义button点击的索引
@property (assign, nonatomic) NSInteger selectedIndex;
@property (weak, nonatomic) IBOutlet UIView *satteView;
@property (weak, nonatomic) IBOutlet NSLayoutConstraint *stateViewXConstraint;

@end

@implementation DongTaiQuanViewController

- (void)viewDidLoad {
    [super viewDidLoad];
    self.selectedIndex = 0;
    // Do any additional setup after loading the view.
}

- (void)didReceiveMemoryWarning {
    [super didReceiveMemoryWarning];
    // Dispose of any resources that can be recreated.
}

- (void)viewDidAppear:(BOOL)animated {
    [super viewWillAppear:YES];
    //找出view上所有的子view
    for (UIView *obj in self.view.subviews) {
        //判断找出button
        if ([obj isKindOfClass:[UIButton class]]) {
            //将obj对象转为UIbutton属性
            UIButton *btn = (UIButton *)obj;
            //初始化将所有的button的字体颜色设置成黑色
            [btn setTitleColor:[UIColor blackColor] forState:UIControlStateNormal];
            //判断找出当前的button
            if (btn.tag == self.selectedIndex + 20) {
                //设置当前的button字体的颜色为蓝色
                [btn setTitleColor:[UIColor blueColor] forState:UIControlStateNormal];
                //按照不同的button获得当前的selectedIndex
                self.selectedIndex = btn.tag - 20;
                //改变stateView约束的X的属性，初始-20 + 不同button的x的值 * selectedIndex
                self.stateViewXConstraint.constant = -20 + (self.view.bounds.size.width / 2) * self.selectedIndex;
                //                NSLog(@"lll%@",self.view.subviews);
                //                NSLog(@"%ld",self.selectedIndex);
            }
        }
    }
}


- (IBAction)chooseLeaveNoteState:(UIButton *)sender {
    //按照不同的button获得当前的selectedIndex
    self.selectedIndex = sender.tag-20;
    //改变stateView约束的X的属性，初始-20 + 不同button的x的值 * selectedIndex
    self.stateViewXConstraint.constant = -20 + (self.view.bounds.size.width / 2) * self.selectedIndex;
    //设置除了当前的button字体的颜色为黑色
    for (UIView *obj in self.view.subviews) {
        if ([obj isKindOfClass:[UIButton class]]) {
            UIButton *btn = (UIButton *)obj;
            [btn setTitleColor:[UIColor blackColor] forState:UIControlStateNormal];
        }
    }
    //设置当前的button的字体颜色为蓝色
    [sender setTitleColor:[UIColor blueColor] forState:UIControlStateNormal];
}

/*
#pragma mark - Navigation

// In a storyboard-based application, you will often want to do a little preparation before navigation
- (void)prepareForSegue:(UIStoryboardSegue *)segue sender:(id)sender {
    // Get the new view controller using [segue destinationViewController].
    // Pass the selected object to the new view controller.
}
*/

@end
